<?php

namespace Common\Model;
use Think\Model;

class MemberModel extends Model{

    public function updateMember($memberID, $nickname = '', $gender = 0, $avatar = '')
    {
        return $this->where(array('member_id' => $memberID))->save(array('nickname' => $nickname, 'gender' => $gender, 'avatar' => $avatar));
    }

    /**
     * 新增或更新
     * 
     * @return boolean fasle 失败 ， int 成功 返回完整的数据
     */
    public function update($data)
    {
        $data = $this->create($data);
        if (empty($data)) {
            return false;
        }
        if (empty($data['member_id'])) {
            $id = $this->add();
            if (! $id) {
                $this->error = '新增出错';
                return false;
            }
            $memberID = $id;
        } else {
            $result = $this->where(array( 'member_id' => $data['member_id'] ))->save($data);
            if (false === $result) {
                $this->error = '更新出错';
                return false;
            }
            $memberID = $data['member_id'];
        }
        
        return $memberID;
    }

}
